package br.mikhas.util.jdbc;

import java.sql.ResultSet;
import java.sql.SQLException;

class SingleRowResultSetExtractor implements ResultSetExtrator<Object> {
	private final RowMapper<Object> rowMapper;

	SingleRowResultSetExtractor(RowMapper<Object> mapper) {
		this.rowMapper = mapper;
	}

	public Object extractData(ResultSet rs) throws JdbcException {

		try {
			rs.next();
			return rowMapper.mapRow(0, rs);
		} catch (SQLException e) {
			throw new RowMappingException(
					"Error while mapping result set row #0", e);
		}
	}
}
